<!-- 进程管控 -->
<template>
  <div>
    <el-row>
      <div style="display:flex;justify-content:space-between;">
        <div>
          <span style="color:#d2d7e3;font-size:25px;margin-top:10px;padding-left:10px;">
            <el-tooltip class="item" effect="dark" placement="right">
              <i class="el-icon-question"></i>
              <div style="width: 420px;" slot="content">运行信任的签名证书程序，将不会上送检测，也不会进行进程阻断</div>
            </el-tooltip>
          </span>
        </div>
      </div>
      <el-table stripe border :data="tableData" row-key="Name" style="width: 100%; margin-top: 15px">
        <el-table-column label="序号" width="60" type="index"
          :index='(index) => { return (index + 1) + (this.pageNum - 1) * this.pageSize }'> </el-table-column>
        <el-table-column label="签名名称" prop="Name" show-overflow-tooltip width="360px"></el-table-column>
        <el-table-column label="厂商" show-overflow-tooltip prop="Factory"></el-table-column>
        <el-table-column label="说明" show-overflow-tooltip prop="Descp"></el-table-column>
        <el-table-column label="推荐操作" show-overflow-tooltip prop="Suggestion"
          :formatter="formatterSuggestion"></el-table-column>
        <el-table-column label="操作" fixed="right" width="120px">
          <template slot-scope="scope">
            <!-- <el-button size="mini" :type="scope.row.Status === 1 ? 'danger' : 'success'" @click="startUp(scope.row, scope.$index)">{{scope.row.Status === 1 ? '关闭' : '开启'}}</el-button> -->
            <el-switch v-model="scope.row.Status" :active-value="1" :inactive-value="0" active-color="#459ffc"
              inactive-color="#6d7074" active-text="开" inactive-text="关"  inline-prompt
              @change="startUp(scope.row, scope.$index)">
            </el-switch>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page=pageNum
        :page-size=pageSize background layout="total, prev, pager, sizes, next, jumper" :total="total">
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
import { connrequest } from '@/api/firstPage'
import elDragDialog from '@/directive/el-drag-dialog' // base on element-ui
export default {
  directives: { elDragDialog },
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      total: 0,
      tableData: [],
    }
  },
  watch: {

  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.getData()
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {
  },
  methods: {
    formatterSuggestion(row) {
      let map = {
        1: '无建议',
        2: '白名单',
        3: '黑名单',
        4: '灰名单',
      }
      return map[row.Suggestion] || ''
    },
    async getData() {
      const data = {
        Paging: {
          QueryPageNo: this.pageNum,
          QueryPageLength: this.pageSize,
        },
      }
      const res = await connrequest('GetProcWhiteCert', data)
      this.tableData = res.Data
      this.total = res.Paging.TotalCount
    },
    startUp(row, index) {
      this.$confirm(`确定${row.Status === 0 ? '关闭' : '开启'}?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const data = {
          Data: [{
            ...row
          }],
        }
        const res = await connrequest('EditProcWhiteCert', data)
        if (res.Status.StatusCode === 0) {
          this.$message({
            type: 'success',
            message: `${row.Status === 1 ? '已开启' : '已关闭'}!`
          });
          this.getData()
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        });
        this.tableData[index].Status = row.Status === 1 ? 0 : 1;
      });
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.pageNum = 1
      this.getData()
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum
      this.getData()
    },
  }
}
</script>
<style lang="scss" >

.el-switch__label * {
  line-height: 1;
  font-size: 12px;
  display: inline-block;
}

.el-switch__label {
  position: absolute;
  display: none;
  color: #fff !important;
  font-size: 12px !important;
}

/*打开时文字位置设置*/
.el-switch__label--right {
  z-index: 1;
  right: 22px;
  
}

/*关闭时文字位置设置*/
.el-switch__label--left {
  z-index: 1;
  left: 20px;
}

/*显示文字*/
.el-switch__label.is-active {
  display: block;
}
</style>